//
//  AddCardVC.m
//  SelfDrivingTravelling-IOS
//
//  Created by Teplot_01 on 16/8/8.
//  Copyright © 2016年 Teplot_01. All rights reserved.
//

#import "AddCardVC.h"

@interface AddCardVC ()
@end

@implementation AddCardVC
{
    UIButton *_getCodeBtn;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = LighterGrayColor;
    self.title = @"填写银行卡信息";
    
    [self initView];
}
- (void)initView{
    UIView *nameView = [[UIView alloc]initWithFrame:CGRectMake(0, 80, KScreenWidth, 35)];
    nameView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:nameView];
    UILabel *nameLb = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 60, 35)];
    nameLb.text = @"姓名";
    [nameView addSubview:nameLb];
    UITextField *nameTF = [[UITextField alloc]initWithFrame:CGRectMake(100, 0, KScreenWidth - 120, 35)];
    nameTF.placeholder = @"请输入姓名";
    [nameView addSubview:nameTF];
    
    UIView *IDView = [[UIView alloc]initWithFrame:CGRectMake(0, 120, KScreenWidth, 35)];
    IDView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:IDView];
    UILabel *IDLb = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 70, 35)];
    IDLb.text = @"银行卡号";
    [IDView addSubview:IDLb];
    UITextField *IDTF = [[UITextField alloc]initWithFrame:CGRectMake(100, 0, KScreenWidth - 120, 35)];
    IDTF.placeholder = @"请输入银行卡号";
    [IDView addSubview:IDTF];
    
    UIView *phoneView = [[UIView alloc]initWithFrame:CGRectMake(0, 170, KScreenWidth, 35)];
    phoneView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:phoneView];
    UILabel *phoneLb = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 60, 35)];
    phoneLb.text = @"手机号";
    [phoneView addSubview:phoneLb];
    UITextField *phoneTF = [[UITextField alloc]initWithFrame:CGRectMake(100, 0, KScreenWidth - 180, 35)];
    phoneTF.placeholder = @"请输入手机号";
    [phoneView addSubview:phoneTF];
    _getCodeBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth - 80, 0, 80, 35)];
    [_getCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
    _getCodeBtn.backgroundColor = Theme_Color;
    _getCodeBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [_getCodeBtn addTarget:self action:@selector(codeBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [phoneView addSubview:_getCodeBtn];
    
    UIView *codeView = [[UIView alloc]initWithFrame:CGRectMake(0, 210, KScreenWidth, 35)];
    codeView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:codeView];
    UILabel *codeLb = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 60, 35)];
    codeLb.text = @"验证码";
    [codeView addSubview:codeLb];
    UITextField *codeTF = [[UITextField alloc]initWithFrame:CGRectMake(100, 0, KScreenWidth - 120, 35)];
    codeTF.placeholder = @"请输入验证码";
    [codeView addSubview:codeTF];
    
    //完成Btn
    UIButton *doneBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 300, KScreenWidth, 35)];
    doneBtn.backgroundColor = [UIColor whiteColor];
    [doneBtn setTitle:@"完成" forState:UIControlStateNormal];
    [doneBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//    doneBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [doneBtn addTarget:self action:@selector(doneBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:doneBtn];
}
//获取验证码
- (void)codeBtnAction{
    //更改button的颜色 并且设置button倒计时
    __block int timeout=30; //倒计时时间
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    dispatch_source_set_event_handler(_timer, ^{
        if(timeout<=0){ //倒计时结束，关闭
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                [_getCodeBtn setBackgroundColor:Theme_Color];
                [_getCodeBtn setTitle:@"发送验证码" forState:UIControlStateNormal];
                _getCodeBtn.userInteractionEnabled = YES;
            });
        }else{
            int seconds = timeout % 60;
            NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                [_getCodeBtn setBackgroundColor:LightGray_Color];
                [_getCodeBtn setTitle:[NSString stringWithFormat:@"%@秒后重试",strTime] forState:UIControlStateNormal];
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:1];
                [UIView commitAnimations];
                _getCodeBtn.userInteractionEnabled = NO;
            });
            timeout--;
        }
    });
    dispatch_resume(_timer);
}
- (void)doneBtnAction{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
